//
//  RightViewController.m
//  MPlayer
//
//  Created by 王俊 on 15/12/15.
//  Copyright © 2015年 王俊. All rights reserved.
//

#import "RightViewController.h"
#import "MMDrawerController.h"
#import "UIViewController+MMDrawerController.h"

#define REUSEID @"wjReuseID"
@interface RightViewController ()

@property(nonatomic,strong) NSArray  *arr;
@end

@implementation RightViewController

- (void)viewDidLoad
{
    self.view.backgroundColor = [UIColor whiteColor];
    [self downLoad];
    [self setUpView];
    
    
}


/*例子
 
 http://www.douban.com/j/app/radio/people?app_name=radio_desktop_win&version=100&type=n
 
 http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.search.suggestion&songid=42822293&format=json&from=ios&version=2.1.1
 
 
 试用：AFSoundManager
 http://yinyueshiting.baidu.com/data2/music/137072432/73169351450216861320.mp3?xcode=fcec64e165f1142352d17b2d9b423fd1
 
 
 */

     
- (void)downLoad
{

    NSURL  *url = [NSURL URLWithString:@"http://www.douban.com/j/app/radio/channels"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSURLSession *session = [NSURLSession sharedSession];
    
    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
    _arr = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil] objectForKey:@"channels"];
    [_tabel reloadData];
    }];
    [task resume];

    
    

    
    
    
}

- (void)setUpView
{
    _tabel = [[UITableView alloc]init];
    _tabel.delegate = self;
    _tabel.dataSource = self;
    _tabel.frame = self.view.frame;
    [_tabel registerClass:[UITableViewCell class] forCellReuseIdentifier:REUSEID];
    [self.view addSubview:_tabel];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _arr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [_tabel dequeueReusableCellWithIdentifier:REUSEID];//[[UITableViewCell alloc]init];
    if (_arr.count > 0) {
        NSString *tmpStr = [_arr[indexPath.row] objectForKey:@"name"];
        cell.textLabel.text = [NSString stringWithString:[tmpStr stringByRemovingPercentEncoding]];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.mm_drawerController toggleDrawerSide:MMDrawerSideRight animated:true completion:nil];
}


@end
